<template>
      <view class="mm">
        <uni-forms
      ref="loginRef"
      v-model="state.formData"
      :rules="state.rules"
      validateTrigger="bind"
    >
      <uni-forms-item name="mobile" label="手机号">
        <uni-easyinput
          placeholder="请输入手机号"
          v-model="state.formData.mobile"
          type="number"
          :inputBorder="false"
        >
        
        </uni-easyinput>
      </uni-forms-item>
      <uni-forms-item name="password" label="密码">
        <uni-easyinput
          type="password"
          placeholder="请输入密码"
          v-model="state.formData.password"
          :inputBorder="false"
        >
        </uni-easyinput>
      </uni-forms-item>
      
      <view class="row"> 
        <view @click="register">注册账号</view>
        <view @click="resetPassword">忘记密码</view>
    </view>
	  <button class="submit" @tap="loginSubmit"> 立即登录 </button>
    <view class="line">
      <view>OR</view>
    </view>
  </uni-forms>


      </view>
  </template>
  
  <script setup>
  import sheep from '@/sheep';
  import {  ref, reactive, unref } from 'vue';
  import { mobile,password } from '@/sheep/validate/form';
 

  const loginRef = ref(null);
  // 数据
  const state = reactive({
    // isMobileEnd: false, // 手机号输入完毕
    formData: {
      mobile: '', // 手机号
      password: '', // 验证码
    },
    rules: {
      password,
      mobile,
    },
  });
// 3.账号登录
const emits = defineEmits(['onConfirm']);
const props = defineProps({
    agreeStatus: {
      type: Boolean,
      default: false,
    },
  });
async function loginSubmit() {
    const validate = await unref(loginRef)
      .validate()
      .catch((error) => {
      });
    if (!validate) return;
    if (!props.agreeStatus) {
      emits('onConfirm', true)
      sheep.$helper.toast('请勾选相关协议');
      return;
    }
  
    const { code } = await sheep.$api.user.accountLogin({
		  account: state.formData.mobile,
	    password: state.formData.password
    });
    if (code === 1) {
		uni.showToast({
			title: '登录成功',
			icon:"none"
		});
    sheep.$router.go('/pages/staff/index/index');
    }
  }
  //跳转注册
  const register = ()=>{
    sheep.$router.go('/pages/public/auth/register');
  }
  const resetPassword =() =>{
    sheep.$router.go('/pages/public/auth/reset_password');
  }
  </script>
  
  <style lang="scss">
  @import '../auth/components/login.scss';
  #app{
    .form-box {justify-content: space-around;

    }
  }



  </style>